package com.gilgamesh.mall.product.sql;

import com.gilgamesh.mall.sdk.bean.product.ImageEntity;
import com.gilgamesh.mall.sdk.util.BeanUtil;
import com.gilgamesh.mall.sdk.util.StringUtil;

/**
 * Created by Peiyao.Wang on 2021/1/13
 *
 * @author Peiyao.Wang
 * @date 2021/1/13
 */

public class ImageSql {
    public String listImages(ImageEntity imageEntity){
        StringBuilder sb = new StringBuilder();
        sb.append("select * from t_image ");
        if(BeanUtil.isLogicalNull(imageEntity)){
            return sb.toString();
        }
        int times = 0;
        if(imageEntity.getId() != null){
            if(times == 0){
                sb.append(" where ");
            }else if(times > 0){
                sb.append(" and ");
            }
            times++;
            sb.append("id = #{id}");
        }
        if(StringUtil.isNotEmpty(imageEntity.getSkuCode())){
            if(times == 0){
                sb.append(" where ");
            }else if(times > 0){
                sb.append(" and ");
            }
            times++;
            sb.append(" sku_code = #{skuCode} ");
        }
        if(StringUtil.isNotEmpty(imageEntity.getProductCode())){
            if(times == 0){
                sb.append(" where ");
            }else if(times > 0){
                sb.append(" and ");
            }
            times++;
            sb.append(" product_code = #{productCode} ");
        }

        if(StringUtil.isNotEmpty(imageEntity.getImageUri())){
            if(times == 0){
                sb.append(" where ");
            }else if(times > 0){
                sb.append(" and ");
            }
            times++;
            sb.append(" image_uri = #{imageUri} ");
        }

        if(imageEntity.getRank() != null){
            if(times == 0){
                sb.append(" where ");
            }else if(times > 0){
                sb.append(" and ");
            }
            times++;
            sb.append(" rank = #{rank} ");
        }

        return sb.toString();
    }

}
